<?php
/**
 * 系统通知
 * @copyright  Copyright (c) 中国追溯
 * @since      File available since Release v1.1
 */

use Shopnc\Tpl;

defined('InShopNC') or exit('Access Invalid!');

class system_informControl extends SystemControl
{

    function __construct()
    {
        parent::__construct();
    }

    public function indexOp()
    {
        $this->informOp();
    }

    public function informOp()
    {
        Tpl::showpage('system_inform.index');
    }

    /**
     * 会员列表
     */
    public function member_listOp() {
        $model_member = Model('member');

        $condition = array();
        $condition['member_name'] = array('like', '%' . $_GET['keyword'] . '%');
        $condition['is_allowtalk'] = array('eq', 1);
        $condition['member_state'] = array('eq', 1);
        $member_list = $model_member->getMemberList($condition, 'member_id,member_name,member_truename,member_avatar', 4);
        Tpl::output('member_list', $member_list);
        Tpl::output('show_page', $model_member->showpage());
        Tpl::showpage('system_inform.members', 'null_layout');
    }

    /**
     * [system_inform_send 发送系统消息]
     * @return [type] [description]
     */
    public function system_inform_sendOp()
    {
        //获取消息接收人id
        $member_id = isset($_POST['member_ids']) ? (string)$_POST['member_ids'] : '';
        $member_id = array_filter(explode(',', $_POST['member_ids']));
        if (empty($member_id)) showMessage('请选择你要发送的对象！');

        //获取消息内容
        $message_body = isset($_POST['message_body']) ? htmlspecialchars_decode($_POST['message_body']) : '';
        if (empty($message_body)) showMessage('抱歉，请填写消息内容！');

        $model_message = Model('message');
        $insert_arr = array();
        $insert_arr['from_member_id'] = 0;
        if (count($member_id) > 1) {
            $insert_arr['message_ismore'] = 1;
            $insert_arr['member_id'] = ',' . implode(',', $member_id) . ',';
        } else {
            $insert_arr['member_id'] = implode(',', $member_id);
        }
        $insert_arr['msg_content'] = $message_body;
        $insert_arr['message_type'] = 1;
        $model_message->saveMessage($insert_arr);
        showMessage('发送成功！');        
    }

}